package com.zxs.xss.servlet;

import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class CachedServletInputStream extends ServletInputStream {
		private final ByteArrayInputStream byteArrayInputStream;

		public CachedServletInputStream(byte[] content) {
			this.byteArrayInputStream = new ByteArrayInputStream(content);
		}

		@Override
		public int read() throws IOException {
			return byteArrayInputStream.read();
		}

		@Override
		public boolean isFinished() {
			return byteArrayInputStream.available() == 0;
		}

		@Override
		public boolean isReady() {
			return true; // Always ready as we are using ByteArrayInputStream
		}

		@Override
		public void setReadListener(ReadListener readListener) {
			throw new UnsupportedOperationException("Not supported.");
		}
	}
